<template>
  <div>
    <el-steps :active="activeStep" finish-status="success" simple style="margin-top: 20px">
      <el-step title="试卷基本信息" />
      <el-step title="添加试题" />
    </el-steps>
    <el-form
      ref="testPaperForm"
      :model="testPaperForm"
      :rules="testPaperRules"
      label-width="120px"
      class="formStyle"
    >
      <div v-if="activeStep==0">
        <el-form-item label="试卷名称" prop="name">
          <el-input v-model="testPaperForm.name" style="width:500px;" />
        </el-form-item>
        <el-form-item label="试卷类型">
          <el-radio-group v-model="testPaperForm.type" tyle="width:500px;">
            <el-radio label="trueTopic">真题</el-radio>
            <el-radio label="modelTopic">模拟题</el-radio>
            <el-radio label="exercise">课后练习</el-radio>
            <el-radio label="work">课后作业</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="答题时间" prop="time">
          <el-input v-model="testPaperForm.time" placeholder="单位：分钟" style="width:500px;" />
        </el-form-item>
        <el-form-item label="总分数" prop="grade">
          <el-input v-model="testPaperForm.grade" placeholder="单位：分" style="width:500px;" />
        </el-form-item>
        <el-form-item label="包含题型" prop="questionTypes">
          <el-checkbox-group v-model="testPaperForm.questionTypes">
            <el-checkbox label="单选题">单选题</el-checkbox>
            <el-checkbox label="多选题">多选题</el-checkbox>
            <el-checkbox label="判断题">判断题</el-checkbox>
            <el-checkbox label="简答题">简答题</el-checkbox>
            <el-checkbox label="不定项">不定项</el-checkbox>
            <el-checkbox label="填空题">填空题</el-checkbox>
            <el-checkbox label="材料题">材料题</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </div>
      <div v-if="activeStep==1">
        <el-form-item label="包含题型">
          <el-radio-group v-model="genre" size="medium">
            <template v-for="(item, index) in testPaperForm.questionTypes">
              <el-radio-button :label="item" :key="index">{{ item }}</el-radio-button>
            </template>
          </el-radio-group>
        </el-form-item>
        <el-row>
          <el-col :span="20">
            <el-form-item label="每题得分">
              <el-input v-model="testPaperForm.score" style="width:200px;" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button v-if="creatTopic==false" type="success" @click="creatTopic=!creatTopic">新增试题</el-button>
            <el-button v-if="creatTopic==true" type="success" @click="creatTopic=!creatTopic">取消新增</el-button>
            <el-button type="success" @click="questionsDialog = true">新增已有试题</el-button>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <div v-if="activeStep==1">
      <singleChoice v-if="genre=='单选题'&& creatTopic==true" />
      <muchChoiceit v-if="genre=='多选题'&& creatTopic==true" />
      <judge v-if="genre=='判断题'&& creatTopic==true" />
      <shortAnswer v-if="genre=='简答题'&& creatTopic==true" />
      <indefinite v-if="genre=='不定项'&& creatTopic==true" />
      <cloze v-if="genre=='填空题'&& creatTopic==true" />
      <material v-if="genre=='材料题'&& creatTopic==true" />
    </div>
    <div style="margin:20px; text-align: center;">
      <el-button v-if="activeStep==0" type="primary" @click="nextStep">保存并继续</el-button>
      <el-button v-if="activeStep==1" type="primary" @click="activeStep=0">提交审核</el-button>
      <el-button @click="activeStep=0">取 消</el-button>
    </div>
    <!-- 新增已有试题弹框 -->
    <el-dialog :visible.sync="questionsDialog" title="提示" width="50%">
      <el-row>
        <el-col :span="12">
          <el-select v-model="chapter" placeholder="请选择章" @change="chapterSearch">
            <el-option
              v-for="item in chapterOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-col>
        <el-col :span="12">
          <el-select v-model="section" placeholder="请选择节" @change="sectionSearch">
            <el-option
              v-for="item in sectionOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-col>
      </el-row>
      <el-row style="margin:20px 0;">
        <el-col>
          <el-input v-model="keyWord" style="width:300px;" />
          <el-button type="primary">查询</el-button>
        </el-col>
      </el-row>
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%;">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="日期" width="120">
          <template slot-scope="scope">{{ scope.row.date }}</template>
        </el-table-column>
        <el-table-column prop="name" label="姓名"></el-table-column>
        <el-table-column prop="address" label="地址"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="questionsDialog = false">取 消</el-button>
        <el-button type="primary" @click="questionsDialog = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import singleChoice from '../components/questiontype/singlechoice'
import muchChoiceit from '../components/questiontype/muchchoiceit'
import judge from '../components/questiontype/judge'
import shortAnswer from '../components/questiontype/shortanswer'
import indefinite from '../components/questiontype/muchchoiceit'
import cloze from '../components/questiontype/cloze'
import material from '../components/questiontype/material'
export default {
  components: {
    singleChoice,
    muchChoiceit,
    judge,
    shortAnswer,
    indefinite,
    cloze,
    material
  },
  data() {
    return {
      activeStep: 0,
      creatTopic: false,
      keyWord: '',
      chapter: '',
      section: '',
      genre: '',
      questionsDialog: false,
      testPaperForm: {
        name: '',
        type: 'trueTopic',
        time: '',
        grade: '',
        score: '',
        questionTypes: []
      },
      tableData: [],
      multipleSelection: [],
      testPaperRules: {
        name: [{ required: true, message: '请输入试卷名称', trigger: 'blur' }],
        time: [{ required: true, message: '请输入答题时间', trigger: 'blur' }],
        grade: [{ required: true, message: '请输入试卷总分数', trigger: 'blur' }],
        questionTypes: [{ required: true, message: '至少选择一种题型', trigger: 'change' }]
      },
      chapterOptions: [
        {
          label: '不限制',
          value: 'noLimit'
        },
        {
          label: '第一章',
          value: 'firstChapter'
        }
      ],
      sectionOptions: [
        {
          label: '不限制',
          value: 'noLimit'
        },
        {
          label: '第一节',
          value: 'firstSection'
        }
      ]
    }
  },
  methods: {
    nextStep() {
      this.$refs.testPaperForm.validate((valid) => {
        if (valid) {
          this.activeStep = 1
        } else {
          return false
        }
      })
    },
    chapterSearch() { },
    sectionSearch() { }
  }
}
</script>
<style lang="scss" scoped>
.formStyle {
  margin: 20px 0;
}
</style>
